﻿using UnityEngine;
using System.Collections;

public class ServerItem : MonoBehaviour {
    public UILabel server;
    public UILabel serverId_label;
    public GameObject selectSprite;
    public UISprite serverType;
   
    ProtoBuf.Message.ConfigServerZone zoneInfo = null;

    public ProtoBuf.Message.ConfigServerZone GetZoneInfo()
    {
        return zoneInfo;
    }

    public int GetZoneId()
    {
        return zoneInfo.serverId;
    }

    public void InitServerItem(ProtoBuf.Message.ConfigServerZone info, UIEventListener.VoidDelegate _onClick)
    {
        this.zoneInfo = info;
        InitServerItem(info.state, info.globalServerKey, info.serverId, info.name, info.display, info.serverId.ToString(), _onClick);
    }

    void InitServerItem(string state, string serverKey, int serverId,string serverName,string display, string serverIp, UIEventListener.VoidDelegate _onclick) 
    {
        server.text = serverName;
        if (string.IsNullOrEmpty(display))
        {
            serverId_label.text = serverId + LanguageTool.GetTextNoUpdate(1062);
        }
        else
        {
            serverId_label.text = display + LanguageTool.GetTextNoUpdate(1062);
        }
       
        //this.state = state;
        if (state == Login.ServerState.normal)//正常
        {
            serverType.spriteName = "UI_denglu_item_hot";
           

        }
        else if (state == Login.ServerState.recommend)//新区
        {
            serverType.spriteName = "UI_denglu_item_new";
           
        }
        else if (state == Login.ServerState.maintain)//维护
        {
            serverType.spriteName = "UI_denglu_item_weihu";
           
        }
        else if (state == Login.ServerState.busy)//爆满
        {
            serverType.spriteName = "UI_denglu_item_hot";
            
        }
        this._onclick = _onclick;
        selectSprite.GetComponent<UIButton>().disabledColor = Color.white;
    }

    UIEventListener.VoidDelegate _onclick;

    void OnClick() {
        _onclick(gameObject);
    }

    public void OnSelectButtonClick() {
        _onclick(gameObject);
    }

    public void DestoryGame() 
    {
        Destroy(this.gameObject);
    }
    
}
